﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quanlytruongtruongtieuhoc
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                clsKetnoi.taoKetnoi();
                timer1.Enabled = true;
                // pbHinnen.Visible = true;
                Annut();
                DateTime ngay = DateTime.Now;
                string ngay1 = ngay.DayOfWeek.ToString() + ", " + ngay.ToShortDateString().ToString();
                btNgay.Text = ngay1;
                SqlCommand com = new SqlCommand("select rtrim(ten_quyen) from quyen where ma_loai_quyen='"+frmDangnhap.quyen+"'", clsKetnoi.con);
                string quyen = com.ExecuteScalar().ToString();
                string ten = frmDangnhap.ho + " " + frmDangnhap.ten+" ("+quyen+")";
                lbTennguoidung.Text = ten;
                txtTaikhoan.Text = frmDangnhap.magv;
                txtTennguoidung.Text = frmDangnhap.ho + " " + frmDangnhap.ten;
                txtChucnang.Text = quyen;
                if (frmDangnhap.quyen == "Q001")
                    isAdmin();
                else if (frmDangnhap.quyen == "Q002")
                    isBGH();
                else if (frmDangnhap.quyen == "Q003")
                    isGiaovien();
                else if (frmDangnhap.quyen == "Q004")
                    isThuquy();
                else if (frmDangnhap.quyen == "Q005")
                    isPhutrach();
                else if (frmDangnhap.quyen == "Q006")
                    isVanphong();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Hiennut()
        {
            btHSGV.Enabled = true;
            btHSHS.Enabled = true;
            btHuongdansudung.Enabled = true;
            btIn.Enabled = true;
            btInluong.Enabled = true;
            btNguoidung.Enabled = true;
            btNhapdiem.Enabled = true;
            btXeplop.Enabled = true;
            btPhancongday.Enabled = true;
            btQuanlynamhoc.Enabled = true;
            btTinhluong.Enabled = true;
            btTKB.Enabled = true;
            btTTCT.Enabled = true;
        }
        private void Annut()
        {
            lbTen.Visible = false;
            gbGiangday.Visible = false;
            gbHSHS.Visible = false;
            gbLuong.Visible = false;
            gbQuanlychung.Visible = false;
            gbTrogiup.Visible = false;
        }
        private void isBGH()
        {
            try
            {
               // btPhancongday.Enabled = false;
              //  btPhancongcn.Enabled = false;
                btTinhluong.Enabled = false;
                btInluong.Enabled = false;
                btNguoidung.Enabled = false;
               // btQuanlynamhoc.Enabled = false;
              //  btHSHS.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void isGiaovien()
        {
            try
            {
                btHSHS.Enabled = false;
                btPhancongday.Enabled = false;
                btXeplop.Enabled = false;
                btTinhluong.Enabled = false;
                btInluong.Enabled = false;
                btNguoidung.Enabled = false;
                btQuanlynamhoc.Enabled = false;
                btHSGV.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void isAdmin()
        {
            Hiennut();
        }
        private void isKetoan()
        {
            btHSHS.Enabled = false;
            btPhancongday.Enabled = false;
            btXeplop.Enabled = false;
            btTinhluong.Enabled = true;
            btInluong.Enabled = true;
            btNguoidung.Enabled = false;
            btQuanlynamhoc.Enabled = false;
            btHSGV.Enabled = false;
            btTKB.Enabled = false;
            btNhapdiem.Enabled = false;
            btIn.Enabled = false;
            btChunhiem.Enabled = false;
        }
        private void isPhutrach()
        {
            btHSHS.Enabled = false;
            btPhancongday.Enabled = false;
            btXeplop.Enabled = false;
            btTinhluong.Enabled = false;
            btInluong.Enabled = false;
            btNguoidung.Enabled = false;
            btQuanlynamhoc.Enabled = false;
            btHSGV.Enabled = false;
            btTKB.Enabled = false;
            btNhapdiem.Enabled = false;
            btIn.Enabled = false;
            btChunhiem.Enabled = false;
        }
        private void isThuquy()
        {
            btHSHS.Enabled = false;
            btPhancongday.Enabled = false;
            btXeplop.Enabled = false;
            btTinhluong.Enabled = false;
            btInluong.Enabled = false;
            btNguoidung.Enabled = false;
            btQuanlynamhoc.Enabled = false;
            btHSGV.Enabled = false;
            btTKB.Enabled = false;
            btNhapdiem.Enabled = false;
            btIn.Enabled = false;
            btChunhiem.Enabled = false;
        }
        private void isVanphong()
        {
            btHSHS.Enabled = false;
            btPhancongday.Enabled = false;
            btXeplop.Enabled = false;
            btTinhluong.Enabled = false;
            btInluong.Enabled = false;
            btNguoidung.Enabled = false;
            btQuanlynamhoc.Enabled = false;
            btHSGV.Enabled = false;
            btTKB.Enabled = false;
            btNhapdiem.Enabled = false;
            btIn.Enabled = false;
            btChunhiem.Enabled = false;
        }
        private void ribbonBar9_ItemClick(object sender, EventArgs e)
        {

        }

        private void btHoso_Click(object sender, EventArgs e)
        {

        }

        private void rbChucnang_Click(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void buttonX2_Click(object sender, EventArgs e)
        {

        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
          DateTime passTime = DateTime.Parse((DateTime.Now).ToString());
          btDongho.Text = passTime.ToLongTimeString().ToString();
        }

        private void trViewMenu_AfterSelect(object sender, TreeViewEventArgs e)
        {
           string a=e.Node.Name.ToString();
           if (a == "DM")
           {
               Form1_Load(sender, e);
               gbNguoidung.Visible = false;
           }
           if (a == "QLC")
           {
               gbNguoidung.Visible = false;
               gbLuong.Visible = false;
               gbQuanlychung.Visible = true;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý chung";
            //   pbHinnen.Visible = false;
               lbTen.Visible = true;
           }
           if (a == "QLNHHK")
           {
               gbNguoidung.Visible = false;
               gbLuong.Visible = false;
               gbQuanlychung.Visible = true;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý chung";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
           }
           if (a == "QLND")
           {
               gbNguoidung.Visible = false;
               gbLuong.Visible = false;
               gbQuanlychung.Visible = true;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý chung";
              // pbHinnen.Visible = false;
               lbTen.Visible = true;
           }
           if (a == "TG")
           {
               gbNguoidung.Visible = false;
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = true;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Trợ giúp";
              // pbHinnen.Visible = false;
               lbTen.Visible = true;
           }
           if (a == "HDSD")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible =true;
               gbHSHS.Visible = false;
               gbGiangday.Visible= false;
               lbTen.Text = "Trợ giúp";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "TTCT")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = true;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Trợ giúp";
              // pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "LUONG")
           {
               gbLuong.Visible = true;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý lương";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "TINHLUONG")
           {
               gbLuong.Visible = true;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Trợ giúp";
              // pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "INLUONG")
           {
               gbLuong.Visible = true;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
               lbTen.Text = "Trợ giúp";
              // pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "QLGD")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "PCCN")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "GDHS")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "TKB")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "ND")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "CN")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
          //     pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "IN")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = true;
               lbTen.Text = "Quản lý giảng dạy";
           //    pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "QLHS")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = true;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý hồ sơ";
            //   pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "HSHS")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = true;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý hồ sơ";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "HSGV")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = true;
               gbGiangday.Visible = false;
               lbTen.Text = "Quản lý hồ sơ";
             //  pbHinnen.Visible = false;
               lbTen.Visible = true;
               gbNguoidung.Visible = false;
           }
           if (a == "TTND")
           {
               gbLuong.Visible = false;
               gbQuanlychung.Visible = false;
               gbTrogiup.Visible = false;
               gbHSHS.Visible = false;
               gbGiangday.Visible = false;
           //    pbHinnen.Visible = false;
               lbTen.Visible = false;
               gbNguoidung.Visible = true;
               lbTen.Visible = false;
           }
        }
        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void gbTrogiup_Enter(object sender, EventArgs e)
        {

        }

        private void btTTCT_Click(object sender, EventArgs e)
        {
            frmThongtin A = new frmThongtin();
            A.ShowDialog();
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void btDoimatkhau_Click(object sender, EventArgs e)
        {
            frmDoimatkhau A = new frmDoimatkhau();
            A.ShowDialog();
        }

        private void lThoat_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult kq = new DialogResult();
            DialogResult kq1 = new DialogResult();
      //      kq1 = MessageBox.Show("Có đăng nhập lại không ?", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            kq = MessageBox.Show("Có chắc thoát không ?", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (kq == DialogResult.OK)
            {
                kq1 = MessageBox.Show("Có muốn đăng nhập lại không ?", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (kq1 == DialogResult.OK)
                {
                    frmDangnhap A = new frmDangnhap();
                    A.Show();
                    this.Hide();
                }
                else
                Application.Exit();
            }
        }

        private void btXemthontin_Click(object sender, EventArgs e)
        {
            frmThongtingiaovien A = new frmThongtingiaovien();
            A.ShowDialog();

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void gbNguoidung_Enter(object sender, EventArgs e)
        {

        }

        private void btNguoidung_Click(object sender, EventArgs e)
        {
            frmQuanlynguoidung A = new frmQuanlynguoidung();
            A.ShowDialog();
        }

        private void btHSGV_Click(object sender, EventArgs e)
        {
            frmHosogiaovien A = new frmHosogiaovien();
            A.Show();
            this.Hide();
        }

        private void btHSHS_Click(object sender, EventArgs e)
        {
            frmHosohocsinh A = new frmHosohocsinh();
            this.Hide();
            A.Show();
        }

        private void btXeplop_Click(object sender, EventArgs e)
        {
            frmXeplop A = new frmXeplop();
            A.Show();
            this.Hide();
        }

        private void btPhancongday_Click(object sender, EventArgs e)
        {
            frmPhanconggiangday A = new frmPhanconggiangday();
            A.Show();
            this.Hide();
        }
    }
}
